<template>

	<view class="kuang">
		<view class="Abox" v-for="(item,index) in physical" :key="index">
			<!-- 用户姓名 -->
			<view class="box">
				<view>
					<text style="font-weight: bold;">{{item.prepeopleName}}</text>
					<text style="padding-left: 30rpx;font-weight: bold;">{{item.prepeoplePhone}}</text>
				</view>
				<view :style="{color
				 :item.preStatus === 1 ? '#0acb00' 
				 :item.preStatus === 2 ? '#ff0004' 
				 :item.preStatus === 3 ? '#4b5bd9' 
				 : '#949494'}" @click="awaitLink(index)" class="await-text">
					{{
					 item.preStatus == 1 ? '待体检' 
				     :item.preStatus == 2 ? '已支付' :'已过期' 
				}}
				</view>
			</view>
			<!-- 用户体检 -->
			<view class="boxB">
				<view>
					<text>体检机构：</text><text>{{item.subOrganName}}</text>
				</view>
				<view>
					<text>体检时间：</text><text>{{item.preTime}}</text>
				</view>
				<view>
					<text>预约单号：</text><text>{{item.preinfoId}}</text>
				</view>
			</view>
		</view>

	</view>
</template>
<script lang="ts" setup>
	import { reactive, ref } from "vue"
	import { request } from "../../utils/request.js"
	interface order {
		preinfoId : number,
		prepeopleName : string,
		prepeoplePhone : number,
		subOrganName : string,
		preTime : string,
		preStatus : number
	}


	let physical : order[] = reactive([])
	const getphy = () =>{
		request("/preinfo/listByUserId?userId=1","get")
		.then((res) =>{
			 console.log(res.data);
			 physical.length = 0
			 physical.push(...res.data)
		})
		.catch((error)=>{
			console.log("请求失败");
		})
	}

	// const getphy = () => {
	// 	uni.request({
	// 		url: 'http://47.109.64.46:8080/patient/preinfo/listByUserId?userId=1',
	// 		success: function (res) {
	// 			console.log(res.data);
	// 			physical.length = 0
	// 			physical.push(...res.data.data)
	// 		}
	// 	})
	// }
	getphy()

	const awaitLink = (index) => {
		console.log(physical[index].preStatus);
		switch (physical[index].preStatus) {
			case 1:
				uni.navigateTo({
					url: "/page_order/order_info/order_info"
				});
				break;
			case 2:
				uni.navigateTo({
					url: "/page_report/report-check/report-check"
				})
				break;
			case 3:
				// 完成
				break;

			case 4:
				// 已过期2
				break;
			case 5:
				// 已取消2
				break;
			case 6:
				// 已退款2
				break;
			default:
				// 默认情况下的操作，已过期
				break;
		}
	}
</script>

<style lang="less" scoped>
	.kuang {
		padding-bottom: 10rpx;
		background-color: #d0d1d1;


		.Abox {

			margin: 20rpx auto;
			width: 720rpx;
			height: 320rpx;
			background-color: #ffffff;

			// background-color: aqua;
			.box {
				display: flex;
				justify-content: space-between;
				line-height: 100rpx;
				width: 620rpx;
				height: 100rpx;
				margin: auto;
			}

			.boxB {
				// width: 700rpx;
				height: 300rpx;
				border-top: 0.5rpx solid #d0d0d0;
				padding-left: 40rpx;
				line-height: 70rpx;
			}
		}
	}
</style>